// JavaScript Document
var filterStr = function(){
    var regStr = /[\'\"\,\<\>\+\*\/\%\^\=\\\!\&\|\(\)\[\]\{\}\;\~\`\#\$]+/;
    var val = $(this).val(),str = '';
    if(regStr.test(val)) {
        str = val.replace(regStr,"");
        $(this).val(str);
    }
    return;
};
function CLen(curLength, obj)
{
    var maxLen=67,obj = obj || $("#CharLen");
    //curLength = $("#content").val().length,
        sj = parseInt(curLength),
        arg =parseInt(sj/maxLen)+1;
    if(sj%maxLen==0) {
        arg =parseInt(sj/maxLen);
    }
    obj.html('当前字符<font color=red>'+curLength+'</font>个,共<font color=red>'+arg+'</font>条计费.最大支持<font color=red>450</font>个字符.每条<font color=red>67</font>字计费');
    return arg;
}
function checkMobileNum(phone) {
    if(!isNaN(phone)){
        if(phone.length == 11){
            var s = phone.substring(0, 2);
            if (s == "13" || s == "14" || s == "15"|| s == "18"){
                return true;
            } else  {
                return false;
            }
        } else {
            return false;
        }
        return false;
    }
}
function template(tpl, val){
    return tpl.replace(/\{(\w+)\}/g, function(m,i){
        if(val[i]) {
            return val[i];
        } else {
            return '';
        }
    })
};
function checkRequired(elem){
    if(elem.value=="")
        return false;
    else
        return true;
}
/*验证百家姓 BEGIN*/
function check_surname(realname){
    var str=realname.substr(0,1); //截取用户提交的用户名的前两字节，也就是姓。
    var surname="赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松 井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双 闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍郤璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东 殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚闫法汝鄢涂钦段干百里东郭南门呼延妫海羊舌微生岳帅缑亢况後有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福";
      var r = surname.search(str);             // 查找字符串。
    if(r==-1){
     return false;
    }
    else{
        return true;
    }
}
/*验证百家姓    END*/
/*验证手机 BEGIN*/
function checkMobile(elem){
    var phone=elem.value;
    if(!isNaN(phone)){
        if(phone.length == 11){
            var s = phone.substring(0, 2);                
            if (s == "13" || s == "14" || s == "15"|| s == "18"){ 
                return true; 
            } else  { 
                return false; 
            }            
        } else {
            return false;
        }
    } else {
        return false;
    }
}
/*验证手机 END*/
//检验手机号码

/*验证固定电话 BEGIN*/
function checkPhone(strPhone)
{ 
    var phone=/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
    var re = new RegExp(phone); 
    if(re.test(strPhone))
    {
        return true;
    }
    else
    {
        return false;
    }
}
/*验证固定电话 END*/
    
 //删除字符串两端的空格
function trim(str){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function getlength(str) {
    var len = 0;
    for(i=0;i<str.length;i++) {
        if(str.charCodeAt(i)>256) {
            len   +=   2;
        }else{
            len++;
        }
    }
    return len;
}
//移除错误信息
function removeError(elem){
if(elem.parentNode.lastChild.className=="error"){
    elem.parentNode.removeChild(elem.parentNode.lastChild);
}
}
//显示错误信息
function showError(elem,msg){
    removeError(elem);
    //生成显示错误信息的span元素
    error=document.createElement("span");
    error.setAttribute("class","error");
    error.appendChild(document.createTextNode(msg));
    elem.parentNode.appendChild(error);
}
    /*是否任何一侧包含空格*/  
  function   isBothSpace(ui)   {  
      var   valid=/(^\s)|(\s$)/;  
      return   (valid.test(ui));}  
   
  /*是否包含空格*/  
function   isIncSpace(ui)   {  
  var   valid=/\s/;  
  if(valid.test(ui)==false)
  {
      alert('有空格！');
  }
 }
  /*是否包含系统禁用的字符*/  
function isIncSym(ui)
{  
  var valid=/[\'\"\,\<\>\+\*\/\%\^\=\\\!\&\|\(\)\[\]\{\}\;\~\`\#\$]+/;  
  if(valid.test(ui.value))
  {//alert('含有非法字符');
       //ui.focus();
      //showError(ui,"不能含有非法字符！");
      alert("不能含有非法字符！");
      var str=ui.value.replace(valid,"");
      ui.value=str;
      return false;
  }
  else
  {
      removeError(ui);
  }
}  
function isTel(num)
{
    if(checkMobile(num.value)==false && checkPhone(num.value)==false)
    {
        //    alert('电话号码不正确');
         showError(num,"电话号码不正确！");
         num.focus();
         return false;
    }
     else
  {
      removeError(num);
  }
}

//费用添加模板
function join_template(id){
        var ob=document.getElementById(id);
          ob.value="费用包含：\n费用不包含：\n购物说明：";
      }
//显示隐藏
function show_msg(num,obj){
    ob=document.getElementById(obj);
    if(ob){
        if(num == 1){
            ob.style.display="block";
        }else{
            ob.style.display="none";    
        }
    }
}
function Selectall() {
    for(var i=0;i<document.ourform.length;i++) {
        if (document.ourform.elements[i].value== "all" ) {
            var c =document.ourform.elements[i];
            break;
        }
     }
    for(var i=0;i<document.ourform.length;i++) {
        var box=document.ourform.elements[i];
        if ((box.name.substr(0,9)=='checkboxs') && (box.checked != c.checked)) {
            box.click();
        }
     }
}
//判断是否为checkbox
function is_checkbox() {
    var Is=false;
    for(var i=0;i<document.ourform.length;i++) {
    var box=document.ourform.elements[i];
    if (box.name.substr(0,9)=='checkboxs' && box.checked==true) {
    Is=true;
    break;
    }
}
    return Is;
}
/*
*验证日期
*/
function checkDate(elem){
    if(!elem.value) return true;
    pattern=/^\d{4}-\d{2}-\d{2}$/;
    if(pattern.test(elem.value)){
        chunk=elem.value.split("-");
        date=new Date(chunk[0],chunk[1]-1,chunk[2]);
        if(date.getFullYear()==chunk[0]&&date.getMonth()+1==chunk[1]&&date.getDate()==chunk[2]){
            return true;
        }else
         return false;
    }
}
/*
*Create By KH
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
        oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i < arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}
function get_childNodes(n,s){
    j=0;
    z=n.childNodes;
    for(i=0;i<z.length;i++){
        if(z[i].nodeType==1){
            if(j==s){
                return z[i];
            }
            j++;
        }
    }
}
function get_firstChild(n){
    y=n.firstChild;
    while (y.nodeType!=1){
    y=y.nextSibling;
    }
    return y;
}
function get_lastChild(n){
    y=n.lastChild;
    while (y.nodeType!=1){
        y=y.previousSibling;
    }
    return y;
}
function get_previoussibling(n){//跨浏览器获取上个节点
    var x=n.previousSibling;
    while (x.nodeType!=1){
        x=x.previousSibling;
    }
    return x;
}
function get_nextsibling(n){//跨浏览器获取下个节点
    var x=n.nextSibling;
    while (x.nodeType!=1){
        x=x.nextSibling;
    }
    return x;
}

function addEvent(e,type,func){//跨浏览器添加事件
    if(e.attachEvent){
        e.attachEvent('on'+type,func)
    }
    else if(e.addEventListener){
            e.addEventListener(type,func,false)
        }
    else{
        e['on'+type] = func;
    }
}
/*Create By KH END*/
/**
*iframe异步加载页面
*/
    var tb_1=false;
    var tb_2=false;
    var tb_3=false;
    var tb_4=false;
    function HoverLi(n){   
        //如果有N个标签,就将i<=N;   
        for(var i=1;i<=3;i++)
        {//全部重写成normaltab与undis,后再设成dis与hovertab;
            document.getElementById('tb_'+i).className='';
            document.getElementById('tbc_0'+i).className='undis';
        }
        document.getElementById('tbc_0'+n).className='dis listinfo';
        document.getElementById('tb_'+n).className='active';
        if(tb_2==false && n==2)
        {
            top.document.getElementById('hiderows').innerHTML='<?=$total_rows?>';
            document.getElementById('tbc_0'+n).innerHTML = "<iframe id='iFrame1' name='iFrame1' height='1' src='jqlisttable.html?act=hide' frameborder='0' scrolling='no' onload='javascript:adjustIframeSize(this);' frameborder='0' width='100%'></iframe>";
            tb_2=true;//防止第二次点击时加截
        }
        if(tb_3==false && n==3)
        {
            document.getElementById('tbc_0'+n).innerHTML = "<iframe id='iFrame2' name='iFrame2' src='jqlisttable.html?act=over' frameborder='0' scrolling='no'  onload='javascript:adjustIframeSize(this);'  frameborder='0' width='100%'></iframe>";
            tb_3=true;
        }
        if(tb_4==false && n==4)
        {
            document.getElementById('tbc_0'+n).innerHTML = "<iframe id='iFrame3' name='iFrame3' src='jqlisttable.html?act=remove' frameborder='0' scrolling='no'  onload='javascript:adjustIframeSize(this);'  frameborder='0' width='100%'></iframe>";
            tb_4=true;
        }
    }
/**
*iframe自适应高度
*/
function adjustIframeSize(frm)
 {
    frm = _$(frm);
    frm.oldID = frm.id;
    frm.id = "iframe_" + (new Date()).valueOf();
    var doc = document.frames ? document.frames[frm.id].document : frm.contentDocument;
            
    if(frm != null && doc != null)
    {
         frm.style.height="0px";//初始化一下,否则会保留大页面高度
         frm.style.height = doc.documentElement.scrollHeight+"px";
         frm.style.width = doc.documentElement.scrollWidth+10+"px";
         doc.body.style.overflowX="hidden";
         doc.body.style.overflowY="hidden";
    }
    frm.id = frm.oldID;
    frm.oldID = null;
}

function _$(element){
    if(typeof element === 'string'){
        return document.getElementById(element);
    }else{
        return element;
    }
}